define("index", ["jquery", "jquery.cookie"], function () {
        var num = 0
        $(".slider").height(2)
        $(".slider").css({
            width: $(".slider").parents("ul").find(".active").width(),
            position: "absolute",
            bottom: 0,
            left: 0,
            background: "red"
        })

        $(".nav_head ul li").on("mouseenter", function () {
            console.log($(this).offset().left);
            $(".slider").stop().animate({
                width: $(this).width(),
                left: $(this).position().left
            })
        })
        $(".nav_head ul ").on("mouseleave", function () {
            console.log(1);
            console.log($(".nav_head ul .active"));
            $(".slider").stop().animate({
                width: $(".nav_head ul .active").width(),
                left: $(".nav_head ul .active").position().left
            })
        })
        console.log($(".slider"));

        function automove() {
            num++;
            console.log(num);
            if (num > 4) num = 0
            $(" .banner ul li").eq(num).siblings().animate({opacity: 0}).removeClass("active").end().animate({opacity: 1}).addClass("active")
            $(" .banner ol li").eq(num).siblings().animate({top: 0}).removeClass("active").end().animate({top: -10}).addClass("active")
        }

        $(".nav .nav_main .list ul li").on("mouseenter", function () {

            $(this).css({
                backgroundColor: "#A90000",
            })
        })
        $(".nav .nav_main .list ul li").on("mouseleave", function () {
            $(this).css({
                backgroundColor: "",
                // backgroundImg:$(this).find("i").css("background")
            })
        })
        $(".toTop").on("click", function () {
            $(window).scrollTop(0, 0)
        })
        $(".nav_head ul li").on("click", function () {
            $(this).siblings().removeClass("active").end().addClass("active")
            return false
        })
        return {
            init: function () {
                $.ajax({
                    url: "../server/isLogin.php",
                }).then(function (res) {
                    console.log(res);
                    if (res.status == 1) {
                        $("a.login").text("欢迎您:" + res.data.user_telphone)

                        let countNum = 0
                        $.ajax({
                            url: "../server/getlist.php",
                            data: {
                                user_id: $.cookie("status")
                            }
                        }).then(function (res) {
                            console.log(res);
                            for (let i = 0; i < res.length; i++) {
                                countNum += parseInt(res[i].pro_num)
                            }
                            $(".cart-nav-list .num").text(countNum)
                        })
                    }
                    else {
                        let countNum = 0
                        let savecookie = JSON.parse($.cookie("cart") || "[]")
                        console.log(savecookie);
                        for (let i = 0; i < savecookie.length; i++) {
                            countNum += savecookie[i].pro_num
                        }
                        $(".cart-nav-list .num").text(countNum)
                    }
                })
                $("a.exit").on("click", function () {
                    $.ajax({
                        url: "http://127.0.0.1/mailegou/server/iQuit.php"
                    }).then(function () {
                        console.log("iQit");
                        $.cookie("status", {}, {expires: -1})
                        window.location.reload()
                    })
                    return false
                })
                $(".settlement").on("click", function () {
                    window.location.href = 'settlement.html';
                    return false
                })
                $(".container").on("click", "img", function () {
                    $.cookie("current", {expires: -1})
                    var goos = {
                        pro_name: $(this).parents("li").find(".pro_name").text(),
                        pro_price: $(this).parents("li").find(".pro_price").text(),
                        pro_imgPath: $(this).parents("li").find(".pro_img")[0].src,
                        pro_id: $(this).parents("li").find(".pro_name").data("id"),
                    }
                    console.log(goos);
                    $.cookie("current", JSON.stringify(goos))
                    window.location.href = 'goos.html';
                    return false
                })
                document.timer = setInterval(() => {
                    automove()
                }, 2000)
                $(".banner ").on("mouseenter", function () {
                    clearInterval(document.timer)
                })
                $(".banner ").on("mouseleave", function () {
                    document.timer = setInterval(() => {
                        automove()
                    }, 2000)
                })
                $(".banner ol li").on("mouseenter", function () {
                    num = $(this).index()
                    $(" .banner ul li").eq(num).siblings().animate({opacity: 0}).removeClass("active").end().animate({opacity: 1}).addClass("active")
                    $(" .banner ol li").eq(num).siblings().stop(true, true).animate({top: 0}).removeClass("active").end().animate({top: -10}).addClass("active")
                })
            }
        }

    }
)